package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 运营数据统计实现类
 */
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private MemberDao memberDao;

    /**
     * 获取运营数据
     *
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReport() {
        try {
            //本日日期
            String today = DateUtils.parseDate2String(DateUtils.getToday());
            //本周一日期
            String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
            //本月一号
            String month = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

            Integer memberCountByToday = memberDao.findMemberCountByDate(today);
            Integer memberCountByMonday = memberDao.findMemberCountAfterDate(monday);
            Integer memberCountByMonth = memberDao.findMemberCountAfterDate(month);
            Integer memberTotalCount = memberDao.findMemberTotalCount();

            Integer orderCountByToday = orderDao.findOrderCountByDate(today);
            Integer orderCountByMonday = orderDao.findOrderCountAfterDate(monday);
            Integer orderCountByMonth = orderDao.findOrderCountAfterDate(month);
            Integer visitsCountByToday = orderDao.findVisitsCountByDate(today);
            Integer visitsCountByMonday = orderDao.findVisitsCountAfterDate(monday);
            Integer visitsCountByMonth = orderDao.findVisitsCountAfterDate(month);

            List<Map> hotSetmeal = orderDao.findHotSetmeal();
            Map<String, Object> map = new HashMap<>();
            map.put("reportDate",today);
            map.put("todayNewMember",memberCountByToday);
            map.put("totalMember",memberTotalCount);
            map.put("thisWeekNewMember",memberCountByMonday);
            map.put("thisMonthNewMember",memberCountByMonth);
            map.put("todayOrderNumber",orderCountByToday);
            map.put("todayVisitsNumber",visitsCountByToday);
            map.put("thisWeekOrderNumber",orderCountByMonday);
            map.put("thisWeekVisitsNumber",visitsCountByMonday);
            map.put("thisMonthOrderNumber",orderCountByMonth);
            map.put("thisMonthVisitsNumber",visitsCountByMonth);
            map.put("hotSetmeal",hotSetmeal);
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
